import 'package:dmz/utils/sp_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../base/pageWidget/base_stateful_widget.dart';
import '../../../base/widget/defult_widget.dart';
import '../../home/model/moto_model.dart';
import '../controller/select_moto_controller.dart';

class SelectMotoPage extends BaseStatefulWidget<SelectMotoController> {
  const SelectMotoPage({super.key});

  @override
  String titleString() => '车辆选择'.tr;

  @override
  List<Widget>? appBarActionWidget(BuildContext context) {
    return [
      DefaultText('保存'.tr, 28.sp, textColor: const Color(0xFF23C565))
          .paddingOnly(right: 32.sp)
          .addGestureDetector(() => null)
    ];
  }

  @override
  get updateId => 'motoSelect';

  @override
  Widget buildContent(BuildContext context) {
    return ListView(
        children: List.generate(
            (controller.motoList?.length ?? 1) - 1,
            (index) => listitem(
                    controller.motoList![index], controller.motoSelect == index)
                .addGestureDetector(() => controller.didSelect(index))));
  }

  Widget listitem(MotoModel data, bool select) {
    return Container(
        decoration: BoxDecoration(
            color: const Color(0xFF434650),
            borderRadius: BorderRadius.circular(46.sp), // 设置圆角半径
            border: Border.all(
              color: select
                  ? const Color(0xFF23C565)
                  : const Color(0xFF434650), // 设置边框颜色
              width: 4.sp, // 设置边框宽度
            )),
        child: Column(children: [
          DefaultText(data.name ?? '', 48.sp,
                  textColor: const Color(0xFFF9F9F9),
                  fontWeight: FontWeight.w700)
              .marginOnly(top: 48.sp, bottom: 6.sp),
          DefaultText(
                  SPUtils.timeIntToTimeStr(data.created_at ?? 0,
                      attern: 'yyyy-MM-dd HH:mm'),
                  28.sp,
                  textColor: const Color(0xFF999999))
              .marginOnly(bottom: 48.sp),
        ])).marginOnly(left: 32.sp, right: 32.sp);
  }
}
